// Learn cc.Class:
//  - https://docs.cocos.com/creator/manual/en/scripting/class.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

cc.Class({
    extends: cc.Component,

    properties: {
        anim: cc.Animation,
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad() {
        // this.icon = cc.find('icon', this.node);
        // this.text = cc.find('text', this.node);
    },

    getIcon(){
        if (this.icon == null) {
            this.icon = cc.find('icon', this.node);
        }
        return this.icon;
    },

    getText(){
        if (this.text == null) {
            this.text = cc.find('text', this.node);
        }
        return this.text;
    },

    hideAllChildren() {
        this.getIcon().active = false;
        this.getText().active = false;
    },

    initEffect(id, effectName, effectInfo) {
        //准备工作
        this.hideAllChildren();
        //
        this.id = id;
        let onFinished = () => {
            //要用到请重赋值此函数
            this.node.removeFromParent();
        };
        //
        switch (effectName) {
            case 'death1': case 'boom1':{
                this.getIcon().active = true;
                break;
            }
            case 'message1': {
                this.getText().getComponent(cc.Label).string = effectInfo;
                this.getText().active = true;
                break;
            }
            default:
                break;
        }
        //播放
        this.anim.once('finished', () => {
            onFinished();
             // ICPC.effectManager.killEffect(id);
        });
        this.anim.play(effectName);

    },

    start() {

    },

    // update (dt) {},
});
